
local maxDistance = achievements.GetValue( "Poor Mans' Sniper", "total", 0 )
local function PlayerKilledByPlayer( msg )
	local victim = msg:ReadEntity()
	local weapon = msg:ReadString()
	local ply = msg:ReadEntity()
	
	if ( ply == LocalPlayer() ) then
		if ( weapon == "weapon_357" ) then
			local distance = math.floor( math.min( ( victim:GetPos() - ply:GetPos() ):Length() / 39.37, 100 ) )
			if ( distance > maxDistance ) then
				maxDistance = distance
				achievements.Update( "Poor Mans' Sniper", maxDistance / 100, maxDistance .. "/100" )
				achievements.SetValue( "Poor Mans' Sniper", "total", maxDistance )
			end
		end
	end
	
	return victim, weapon, ply
end
usermessage.AddHook( "PlayerKilledByPlayer", "Achievements.PoorMansSniper", PlayerKilledByPlayer )

achievements.Register( "Poor Mans' Sniper", "Use the 357 to shoot and kill another player more than 100 meters away.", "achievements/poormanssniper", maxDistance / 100, maxDistance .. "/100" )
